package com.ludomancy.spaceopera;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import com.ludomancy.gamelib.ui.Button;
import com.ludomancy.gamelib.ui.DialogWidget;
import com.ludomancy.gamelib.ResourceManager;
import com.ludomancy.gamelib.Utils;
import com.ludomancy.gamelib.Widget;
import com.ludomancy.gamelib.ui.Button.ButtonListener;

public class StoryWidget extends DialogWidget implements ButtonListener
{
	DialogWidget.DialogListener listener;
	
	private static final Rectangle area = new Rectangle(80,5,400,85);
	private static final Rectangle pictureRect = new Rectangle(area.x + 5,area.y + 5,60,50);
	private static final Rectangle textRect = new Rectangle(pictureRect.x + pictureRect.width + 10,area.y + 5,area.width-30-pictureRect.width,60);
	private static final Rectangle buttonRect = new Rectangle(pictureRect.x,pictureRect.y+pictureRect.height+5,pictureRect.width,20);

	private String brief;
	
	public StoryWidget(Widget parent, Rectangle area, String brief, String buttonLabel, DialogWidget.DialogListener listener)
	{
		super(parent, area);
		this.listener = listener;
		this.brief = brief;

		// button
		Button ok = new Button(this, buttonRect,buttonLabel, this);
		
		initDialog(new Widget[]{ok});
		SpaceOperaApp.app.gameCanvas.setCursor(true);
	}
	
	public void paint(Graphics g)
	{
		Utils.pushAlpha(g, 0.1f);
		g.setColor(Color.BLACK);
		g.fillRect(0,0,getWidth(),getHeight());
		Utils.popAlpha(g);
		GameTheme.theme.fillUIBackground(g, area);
		g.drawImage(ResourceManager.getImage("intro.png"), pictureRect.x, pictureRect.y, null);
		GameTheme.theme.drawShadowText(g, brief, textRect.width, textRect.x, textRect.y);
	}

	public void onPress(Button widget)
	{
		SpaceOperaApp.app.gameCanvas.setCursor(false);
		listener.onDialogClosed(this);
		close();
	}
}
